package com.jt.www.remote;

import com.jt.www.model.reps.GenericListResponse;
import config.FeignConfiguration;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@FeignClient(value = "claimcenter-svc", url = "${remote.files_client_claim_url}",
        configuration = FeignConfiguration.class,
        fallbackFactory = CaseClient.FeignClientFallbackFactory.class)
public interface CaseClient {

    /**
     * 查询是否报案
     *
     * @param policyNos
     * @return
     */
    @GetMapping(value = "/claimcenter/BCaseMain/v1/selectCaseByPolicyNo", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
    ResponseEntity<GenericListResponse<String>> selectCaseByPolicyNo(@RequestParam("policyNos") List<String> policyNos);


    @Component
    class FeignClientFallbackFactory implements FallbackFactory<CaseClient> {

        public static final Logger log = LoggerFactory.getLogger(FeignClientFallbackFactory.class);

        @Override
        public CaseClient create(Throwable cause) {

            return new CaseClient() {
                @Override
                public ResponseEntity<GenericListResponse<String>> selectCaseByPolicyNo(List<String> policyNos) {
                    log.error("{}-调用案件中心查询有无报案记录失败,fallback reason:", "selectCaseByPolicyNo", cause);
                    return null;
                }

            };
        }
    }
}
